/**
 * 简谱打谱软件 - UI组件模块
 */

// 确认导出PDF
function confirmExportPDF() {
  const { jsPDF } = window.jspdf;
  const doc = new jsPDF({
    orientation: document.getElementById('pdf-orientation').value,
    unit: 'mm',
    format: document.getElementById('pdf-size').value
  });
  
  // 显示加载状态
  const confirmBtn = document.getElementById('confirm-export-btn');
  confirmBtn.disabled = true;
  confirmBtn.innerHTML = '<i class="fa fa-spinner fa-spin mr-1"></i> 导出中...';
  
  html2canvas(document.getElementById('sheet-content'), {
    scale: 2,
    useCORS: true,
    logging: false
  }).then(canvas => {
    const imgData = canvas.toDataURL('image/png');
    const imgWidth = doc.internal.pageSize.getWidth();
    const imgHeight = canvas.height * imgWidth / canvas.width;
    
    doc.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight);
    
    // 保存PDF
    const filename = document.getElementById('pdf-filename').value.trim() || '简谱';
    doc.save(`${filename}.pdf`);
    
    // 恢复按钮状态
    confirmBtn.disabled = false;
    confirmBtn.innerHTML = '确认导出';
    
    // 关闭对话框
    closeExportModal();
    
    // 显示成功通知
    showNotification(`PDF已导出为 "${filename}.pdf"`, 'success');
  }).catch(error => {
    console.error('导出PDF失败:', error);
    showNotification('导出PDF失败，请重试！', 'error');
    
    // 恢复按钮状态
    confirmBtn.disabled = false;
    confirmBtn.innerHTML = '确认导出';
  });
}
    